package com.web.dao;

import com.web.controller.web.WebRechargeController;
import com.web.controller.web.WebSysLogController;
import com.web.entity.RechargeRecord;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author FDjavaone
 */
public class RechargeRecordSqlProvider {

    public String insertSelective(RechargeRecord record) {
        BEGIN();
        INSERT_INTO("t_recharge_record");
        
        if (record.getOutTradeNo() != null) {
            VALUES("out_trade_no", "#{outTradeNo,jdbcType=VARCHAR}");
        }

        if (record.getName() != null) {
            VALUES("name", "#{name,jdbcType=VARCHAR}");
        }

        if (record.getPhone() != null) {
            VALUES("phone", "#{phone,jdbcType=VARCHAR}");
        }

        if (record.getType() != null) {
            VALUES("type", "#{type,jdbcType=INTEGER}");
        }
        
        if (record.getAmount() != null) {
            VALUES("amount", "#{amount,jdbcType=DECIMAL}");
        }
        
        if (record.getmId() != null) {
            VALUES("m_id", "#{mId,jdbcType=BIGINT}");
        }
        
        if (record.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }
        
        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getModifyTime() != null) {
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(RechargeRecord record) {
        BEGIN();
        UPDATE("t_recharge_record");
        
        if (record.getOutTradeNo() != null) {
            SET("out_trade_no = #{outTradeNo,jdbcType=VARCHAR}");
        }

        if (record.getName() != null) {
            SET("name = #{name,jdbcType=VARCHAR}");
        }

        if (record.getPhone() != null) {
            SET("phone = #{phone,jdbcType=VARCHAR}");
        }

        if (record.getType() != null) {
            SET("type = #{type,jdbcType=INTEGER}");
        }
        
        if (record.getAmount() != null) {
            SET("amount = #{amount,jdbcType=DECIMAL}");
        }
        
        if (record.getmId() != null) {
            SET("m_id = #{mId,jdbcType=BIGINT}");
        }
        
        if (record.getStatus() != null) {
            SET("status = #{status,jdbcType=INTEGER}");
        }
        
        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getModifyTime() != null) {
            SET("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }
        
        WHERE("id = #{id,jdbcType=BIGINT}");
        
        return SQL();
    }

    public String selectAllRechages(WebRechargeController.RechargeColumns record) {

        BEGIN();
        SELECT("id");
        SELECT("out_trade_no");
        SELECT("name");
        SELECT("phone");
        SELECT("type");
        SELECT("amount");
        SELECT("m_id");
        SELECT("status");
        SELECT("create_time");
        SELECT("modify_time");
        FROM("t_recharge_record");
        if (record.getOutTradeNo() != null && !"".equals(record.getOutTradeNo())) {
            WHERE("out_trade_no like #{outTradeNo,jdbcType=VARCHAR}");
        }
        if (record.getName() != null && !"".equals(record.getName())) {
            WHERE("name like #{name,jdbcType=VARCHAR}");
        }
        if (record.getPhone() != null && !"".equals(record.getPhone())) {
            WHERE("phone like #{phone,jdbcType=VARCHAR}");
        }
        if (record.getType() != null && !"".equals(record.getType())) {
            WHERE("type = #{type,jdbcType=INTEGER}");
        }

        if (record.getStatus() != null && !"".equals(record.getStatus())) {
            WHERE("status = #{status,jdbcType=INTEGER}");
        }

        if(record.getBegin_createTime()!=null){
            WHERE("create_time >= #{begin_createTime,jdbcType=TIMESTAMP}");
        }
        if(record.getEnd_createTime()!=null){
            WHERE("create_time <= #{end_createTime,jdbcType=TIMESTAMP}");
        }

        ORDER_BY("create_time desc");

        return SQL();
    }
}